package belf.migrate.api.taskconf;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.*;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ColumnRule {
    @JsonProperty("rule")
    private String ruleName; // 规则名称，如常见日期时间格式识别

    @JsonProperty("ruleType")
    private RuleType ruleType;

    @JsonProperty("ruleContent")
    private String ruleContent;


    public String toJson() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writer().writeValueAsString(this);
    }


    @Getter
    public enum RuleType {
        DEFAULT("DEFAULT", "默认"),
        SCRIPT_GROOVY("SCRIPT_GROOVY", "Groovy脚本"),
        FUNCTION("FUNCTION", "数据库函数");

        private final String name;
        private final String desc;

        RuleType(String name, String desc) {
            this.name = name;
            this.desc = desc;
        }

    }
}
